package cn.itrip.order.controller;
import cn.itrip.order.service.HotelRoomService;
import cn.itrip.order.service.ImageService;
import cn.itrip.vo.ItripImageVO;
import cn.itrip.vo.hotel.HotelVideoDescVO;
import cn.itrip.vo.hotel.ItripSearchDetailsHotelVO;
import cn.itrip.vo.hotel.ItripSearchFacilitiesHotelVO;
import cn.itrip.vo.hotel.ItripSearchPolicyHotelVO;
import cn.itrip.dto.Dto;
import cn.itrip.order.service.HotelService;
import cn.itrip.pojo.ItripAreaDic;
import cn.itrip.pojo.ItripLabelDic;
import cn.itrip.utlis.DtoUtils;
import cn.itrip.utlis.ErrorCode;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by LENOVO on 2018/8/24.
 */
@Controller
@RequestMapping("/api")
public class HotelInfoController {

    @Resource
    private HotelService hotelService;
    @Resource
    private HotelRoomService hotelRoomService;
    /**
     * 根据条件查询热门城市
     * @param isChina
     * @return
     */
    @ApiOperation(value="根据条件查询热门城市",httpMethod = "GET", protocols = "HTTP", produces = "application/json", response = Dto.class,notes="根据条件查询热门城市")
    @RequestMapping(value = "/hotel/queryhotcity/{isChina}", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto queryHotCity(@PathVariable Integer isChina)
    {
        List<ItripAreaDic> itripAreaDics=null;
        try {
            if(isChina!=null)
            {
                Map condition = new HashMap();
                condition.put("isHot", 1);
                condition.put("isChina", isChina);
                itripAreaDics =hotelService.getHotCityByCondition(condition);
            }
            else
            {
                DtoUtils.returnFail("国内国外id为空", ErrorCode.BIZ_ID_NULL);
            }
        } catch (Exception e) {
            DtoUtils.returnFail("查询热门城市异常", ErrorCode.BIZ_EXCEPTION);
            e.printStackTrace();
        }
        return  DtoUtils.returnDataSuccess(itripAreaDics);
    }

    /**
     * 查询商圈
     * @return
     */
    @ApiOperation(value="查询商圈",httpMethod = "GET", protocols = "HTTP", produces = "application/json", response = Dto.class,notes="查询商圈")
    @RequestMapping(value = "/hotel/querytradearea/{parent}", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto queryTradeArea(@PathVariable Integer parent)
    {
        List<ItripAreaDic> list=null;
        try {
               if(parent!=null)
               {
                   Map condition = new HashMap();
                   condition.put("isTradingArea",1);
                   condition.put("parent", parent);
                   list =hotelService.getTradeAreaByCondition(condition);
                }
               else
               {
                   DtoUtils.returnFail("id为空", ErrorCode.BIZ_ID_NULL);
               }
            } catch (Exception e) {
               DtoUtils.returnFail("查询商圈异常", ErrorCode.BIZ_EXCEPTION);
                e.printStackTrace();
            }
        return  DtoUtils.returnDataSuccess(list);
    }

    /**
     * 查询酒店特色
     * @return
     */
    @ApiOperation(value="查询酒店特色",httpMethod = "GET", protocols = "HTTP", produces = "application/json", response = Dto.class,notes="查询酒店特色")
    @RequestMapping(value = "/hotel/queryhotelfeature", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto queryHotelFeature()
    {
        List<ItripLabelDic> itripHotelFeature=null;
        try {
                Map condition = new HashMap();
                condition.put("parentId", 16);
                itripHotelFeature =hotelService.getHotelFeatureByCondition(condition);
        } catch (Exception e) {
            DtoUtils.returnFail("查询酒店特色异常", ErrorCode.BIZ_EXCEPTION);
            e.printStackTrace();
        }
        return  DtoUtils.returnDataSuccess(itripHotelFeature);
    }

    /**
     * 查询视频描述信息(查询酒店特色、商圈、酒店名称)
     * @return
     */
    @ApiOperation(value="查询视频描述信息",httpMethod = "GET", protocols = "HTTP", produces = "application/json", response = Dto.class,notes="查询视频描述信息")
    @RequestMapping(value = "/hotel/getvideodesc/{id}", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto getVideoDesc(@PathVariable Integer id)
    {
        HotelVideoDescVO hotelVideoDescVO=null;
        try {
            Map condition = new HashMap();
            condition.put("id", id);
            hotelVideoDescVO =hotelService.getVideoDescByHotelId(condition);
        } catch (Exception e) {
            DtoUtils.returnFail("查询视频描述异常", ErrorCode.BIZ_EXCEPTION);
            e.printStackTrace();
        }
        return  DtoUtils.returnDataSuccess(hotelVideoDescVO);
    }

    /**
     * 根据酒店id查询特色和介绍
     * @param id
     * @return
     */
    @ApiOperation(value="根据酒店id查询特色和介绍",httpMethod = "GET", protocols = "HTTP", produces = "application/json", response = Dto.class,notes="根据酒店id查询特色和介绍")
    @RequestMapping(value = "/hotel/queryhoteldetails/{id}", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto queryHotelDetails(@PathVariable Integer id) {
        List<ItripSearchDetailsHotelVO> itripSearchDetailsHotelVOList = null;
        try {
            Map condition = new HashMap();
            condition.put("id", id);
            itripSearchDetailsHotelVOList = hotelService.getHotelDetails(condition);
        } catch (Exception e) {
            DtoUtils.returnFail("根据酒店id查询特色和介绍异常", ErrorCode.BIZ_EXCEPTION);
            e.printStackTrace();
        }
        return DtoUtils.returnDataSuccess(itripSearchDetailsHotelVOList);
    }

    /**
     * 根据酒店id查询酒店设备
    * @param id
    * @return
    */
    @ApiOperation(value="查询酒店设备",httpMethod = "GET", protocols = "HTTP", produces = "application/json", response = Dto.class,notes="查询酒店设备")
    @RequestMapping(value = "/hotel/queryhotelfacilities/{id}", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto queryHotelFacilities(@PathVariable Integer id) {
        ItripSearchFacilitiesHotelVO itripSearchFacilitiesHote = null;
        try {
            Map condition = new HashMap();
            condition.put("id", id);
            itripSearchFacilitiesHote = hotelService.getHotelFacilities(condition);
        } catch (Exception e) {
            DtoUtils.returnFail("根据酒店id查询酒店设备异常", ErrorCode.BIZ_EXCEPTION);
            e.printStackTrace();
        }
        return DtoUtils.returnDataSuccess(itripSearchFacilitiesHote.getFacilities());
    }
    /**
     * 根据酒店id查询酒店政策
     * @param id
     * @return
     */
    @ApiOperation(value="查询酒店政策",httpMethod = "GET", protocols = "HTTP", produces = "application/json", response = Dto.class,notes="查询酒店政策")
    @RequestMapping(value = "/hotel/queryhotelpolicy/{id}", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto queryHotelPolicy(@PathVariable Integer id) {
        ItripSearchPolicyHotelVO itripSearchFacilitiesHote = null;
        try {
            Map condition = new HashMap();
            condition.put("id", id);
            itripSearchFacilitiesHote = hotelService.getHotelHotelPolicy(condition);
        } catch (Exception e) {
            DtoUtils.returnFail("根据酒店id查询酒店政策异常", ErrorCode.BIZ_EXCEPTION);
            e.printStackTrace();
        }
        return DtoUtils.returnDataSuccess(itripSearchFacilitiesHote.getHotelPolicy());
    }

    /**
     * 查询酒店图片
     * @param targetId
     * @return
     */
    @ApiOperation(value="查询酒店图片",httpMethod = "GET", protocols = "HTTP", produces = "application/json", response = Dto.class,notes="查询酒店图片")
    @RequestMapping(value = "/hotel/getimg/{targetId}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto<Object> getImgByTargetId(@PathVariable String targetId) {
            List<ItripImageVO> itripImageVOList = null;
            Map<String, Object> param = new HashMap();
            param.put("type", "0");
            param.put("targetId", targetId);
            try {
                itripImageVOList = hotelRoomService.getImageListByByTargetId(param);
                return DtoUtils.returnSuccess("获取酒店图片成功", itripImageVOList);
            } catch (Exception e) {
                e.printStackTrace();
                return DtoUtils.returnFail("获取酒店图片失败", "100212");
            }
    }
}
